package com.ziven.common.widget.value;

import android.view.View;

import androidx.annotation.NonNull;

import com.ziven.easygo.util.ViewHelper;

/**
 * @author Ziven
 */
public final class ViewValue extends Value {

    public static ViewValue nullView() {
        return new ViewValue();
    }

    public static ViewValue view(View view) {
        return new ViewValue().accept(my -> my.value = view);
    }

    public static ViewValue view(int viewId) {
        return new ViewValue().accept(my -> my.viewId =  viewId);
    }

    public static ViewValue[] views(View... views) {
        ViewValue[] values = new ViewValue[views.length];
        for(int i=0; i<views.length; i++) {
            values[i] = view(views[i]);
        }
        return values;
    }

    public static ViewValue[] views(int... viewIds) {
        ViewValue[] values = new ViewValue[viewIds.length];
        for(int i=0; i<viewIds.length; i++) {
            values[i] = view(viewIds[i]);
        }
        return values;
    }

    private ViewValue() {}

    @Override
    protected void takeEffect(@NonNull ViewHelper<? extends android.view.View> helper) {
        if(value == null) {
            value = helper.getView();
        }
    }

    public View view() {
        return value(View.class);
    }

    public ViewHelper<View> viewHelper() {
        return ViewHelper.create(view());
    }
}
